home *** CD-ROM | disk | FTP | other *** search
- /* SICN LDEF
-
- ©1991 Apple Computer, Inc.
- written by Steven Falkenburg 5/23/91
- This LDEF displays small icons to the left of text in a list.
-
- The small icon is stored in the first 16 bytes of each cell.
- */
-
- #include <Types.h>
- #include <QuickDraw.h>
- #include <Lists.h>
- #include <Memory.h>
-
- /* constants for spacing */
-
- #define kLeftOffset 2
- #define kTopOffset 0
- #define kIconSpace 2
-
- /* prototypes */
-
- void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort);
-
- /* main LDEF entry point */
-
- pascal void theLDEF(short lMessage,Boolean lSelect,Rect *lRect,Cell lCell,
- short lDataOffset,short lDataLen,ListHandle lHandle)
- {
- FontInfo fontInfo; /* font information (ascent/descent/etc) */
- ListPtr listPtr; /* pointer to store dereferenced list */
- SignedByte hStateList,hStateCells; /* state variables for HGetState/SetState */
- Ptr cellData; /* points to start of cell data for list */
- Ptr theSICN; /* points to SICN to be drawn */
- short leftDraw,topDraw; /* left/top offsets from topleft of cell */
-
- /* lock and dereference list mgr handles */
-
- hStateList = HGetState((Handle)lHandle);
- HLock((Handle)lHandle);
- listPtr = *lHandle;
- hStateCells = HGetState(listPtr->cells);
- HLock(listPtr->cells);
- cellData = *(listPtr->cells);
-
- switch (lMessage) {
- case lInitMsg:
- /* we don't need any initialization */
- break;
-
- case lDrawMsg:
- EraseRect(lRect);
-
- if (lDataLen > 0) {
-
- /* determine starting point for drawing */
-
- leftDraw = lRect->left+listPtr->indent.h+kLeftOffset;
- topDraw = lRect->top+listPtr->indent.v+kTopOffset;
-
- /* plot SICN (first 32 bytes) */
-
- if (lDataLen > 32) {
- theSICN = cellData+lDataOffset;
- DrawSICN(theSICN,leftDraw,topDraw,listPtr->port);
- lDataOffset += 32;
- lDataLen -= 32;
- }
- leftDraw += 16+kIconSpace;
-
- /* plot text (offset 32 bytes onward) */
-
- GetFontInfo(&fontInfo);
- MoveTo(leftDraw,topDraw+fontInfo.ascent);
-
- /* set condensed mode if necessary (if the text doesn't fit otherwise) */
-
- TextFace(0);
- if (TextWidth(cellData,lDataOffset,lDataLen) > (lRect->right - leftDraw))
- TextFace(condense);
-
- DrawText(cellData,lDataOffset,lDataLen);
- }
-
- if (!lSelect)
- break;
-
- case lHiliteMsg:
- InvertRect(lRect);
- break;
-
- case lCloseMsg:
- break;
- }
-
- HSetState((Handle)listPtr->cells,hStateCells);
- HSetState((Handle)lHandle,hStateList);
- }
-
-
- /* this procedure draws a small icon using CopyBits */
-
- void DrawSICN(Ptr theSICN,short left,short top,GrafPtr drawPort)
- {
- BitMap iconMap;
- Rect destRect;
-
- iconMap.baseAddr = theSICN;
- iconMap.rowBytes = 2;
- SetRect(&iconMap.bounds,0,0,16,16);
- SetRect(&destRect,0,0,16,16);
- OffsetRect(&destRect,left,top);
- CopyBits(&iconMap,&drawPort->portBits,&iconMap.bounds,&destRect,
- srcCopy,nil);
- }
-